<!--  -->
<template>
  <div class="app-main-container">
    <div class="app-main-title">{{ $t('message.cpsz') }}
      <div class="goback" @click="goBack">
        <i class="el-icon-refresh-left" /> {{ $t('message.fhsyy') }}
      </div>
    </div>
    <div class="doumee-filter">
      <el-form inline>
        <el-form-item :label="$t('message.cpmc2')">
          <el-input v-model="filters.goodsName" :placeholder="$t('message.qsr') + $t('message.cpmc2')" clearable />
        </el-form-item>
        <el-form-item :label="$t('message.cpzt')">
          <el-select v-model="filters.checkGoodsStatus" :placeholder="$t('message.qxz') + $t('message.cpzt')" clearable>
            <el-option
              v-for="item in filters.goodsStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button v-preventReClick type="primary" @click="handleFilter">{{ $t('message.cz') }}</el-button>
          <el-button v-preventReClick @click="clear">{{ $t('message.clear') }}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="goosmanager-space-box">
      <div class="box-item goodstype">
        <div class="item-title df_sb">
          <span>{{ $t('message.cpfl') }}</span>
          <el-button
            v-preventReClick
            type="primary"
            size="small"
            @click="addGoodsType"
          >
            <i class="el-icon-plus" />{{ $t('message.tjfl') }}
          </el-button>
        </div>
        <div style="height: 500px; overflow: auto">
          <div
            v-for="item in goodsType"
            :key="item.id"
            :class="
              selectGoodsTypeInfo.id === item.id
                ? 'goodstype-item active'
                : 'goodstype-item'
            "
            @click="selectGoodsType(item)"
          >
            <div class="title">{{ item.name }}</div>
            <template>
              <el-popover
                v-model="item.visible"
                placement="top"
                trigger="hover"
                :hover="item.visible"
              >
                <div class="popItems">
                  <el-button

                    v-preventReClick
                    size="mini"
                    type="primary"
                    @click="visible = false"
                    @click.stop="toEditGoodsType(item)"
                  >{{ $t('message.edit') }}</el-button>
                  <el-button

                    v-preventReClick
                    type="danger"
                    size="mini"
                    @click="visible = false"
                    @click.stop="toDeleteGoodsType(item)"
                  >{{ $t('message.del') }}</el-button>
                </div>
                <el-button slot="reference" type="info" size="small">
                  <i class="el-icon-more" />
                </el-button>
              </el-popover>
            </template>
          </div>
        </div>
      </div>
      <div v-if="goodsType.length" class="box-item goodsinfo">
        <el-button v-if="true" v-preventReClick type="primary" @click="addGoods">{{ $t('message.xzcp') }}</el-button>
        <el-button v-if="true" v-preventReClick type="primary" @click="inBatch">{{ $t('message.pldr') }}</el-button>
        <el-button v-preventReClick type="primary" @click="showSKU">{{ $t('message.gggl') }}</el-button>
        <el-table
          v-loading="listLoading"
          :data="goodsList"
          element-loading-text="Loading"
          border
          fit
          :header-row-class-name="'table-header'"
          class="doumee-element-table margin-t-20"
        >
          <el-table-column
            align="center"
            :label="$t('message.cptp')"
            min-width="140"
            prop="avatar"
          >
            <template slot-scope="scope">
              <el-image
                fit="contain"
                :src="scope.row.picture"
                :preview-src-list="[scope.row.picture]"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            :label="$t('message.cpmc2')"
            min-width="140"
            prop="name"
            show-overflow-tooltip
          />

          <el-table-column
            align="center"
            :label="$t('message.cpfl')"
            show-overflow-tooltip
            prop="classifyName"
            min-width="100"
          />
          <el-table-column
            align="center"
            :label="$t('message.cpkc')"
            prop="stock"
            min-width="100"
          />
          <el-table-column
            align="center"
            :label="$t('message.cpjg') + '（' + $t('message.yuan') + '）'"
            prop="price"
            min-width="120"
          />
          <el-table-column
            align="center"
            :label="$t('message.txm')"
            prop="barCode"
            show-overflow-tooltip
            min-width="200"
          />
          <el-table-column align="center" :label="$t('message.hyjg')" min-width="100">
            <template slot-scope="scope">
              <el-popover placement="top-start" width="300" trigger="click">
                <div class="pre">
                  <div class="discount-title">{{ $t('message.hyzk') }}</div>
                  {{ discountInfo }}
                </div>
                <el-button
                  slot="reference"
                  v-preventReClick
                  type="text"
                  @click="toShow(scope)"
                >{{ $t('message.djck') }}</el-button>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('message.status')" min-width="80">
            <template slot-scope="scope">
              {{ scope.row.status == "1" ? $t('message.shanjia') : $t('message.xiajia') }}
            </template>
          </el-table-column>
          <el-table-column
            :label="$t('message.caozuo')"
            min-width="250"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <div v-if="scope.row.status == '0'" class="flex-cc">
                <el-button
                  v-if="true"
                  v-preventReClick
                  type="text"
                  @click="toEdit(scope.row.id)"
                >{{ $t('message.edit') }}</el-button>
                <el-button
                  v-if="true"
                  v-preventReClick
                  type="text"
                  @click="editStatus(scope.row.id, scope.row.status)"
                >{{ scope.row.status == "1" ? $t('message.xiajia') : $t('message.shanjia') }}</el-button>
                <el-button
                  v-if="true"
                  v-preventReClick
                  type="text"
                  class="secondColor"
                  @click="toDelete(scope.row.id)"
                >{{ $t('message.del') }}</el-button>
              </div>
              <div v-if="scope.row.status == '1'" class="flex-cc">
                <el-button
                  v-if="true"
                  v-preventReClick
                  type="text"
                  @click="editStatus(scope.row.id, scope.row.status)"
                >{{ scope.row.status == "1" ? $t('message.xiajia') : $t('message.shanjia') }}</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <Paginations
          :total="totalCount"
          :page="pagination.page"
          @current-change="handleCurrentChange"
          @SizeChange="pageSizeChange"
        />
      </div>
    </div>
    <el-dialog
      :title="goodsTypeAddEdit ? $t('message.tjfl') : $t('message.bjfl')"
      :visible.sync="showAddGoodsType"
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      @close="cancelAddGoodsType"
    >
      <el-form ref="form" :model="goodsTypeInfo" :rules="rules" label-width="auto" label-suffix="：">
        <el-form-item :label="$t('message.flmc')" prop="name">
          <el-input v-model="goodsTypeInfo.name" :maxlength="50" :placeholder="$t('message.qsr') + $t('message.flmc')" />
        </el-form-item>
        <el-form-item :label="$t('message.sort')" prop="sort">
          <el-input v-model="goodsTypeInfo.sort" oninput="value=value.replace(/^(0+)|[^\d]+/g, '').slice(0, 8)" :placeholder="$t('message.qsr') + $t('message.sort')" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showAddGoodsType = false">{{ $t('message.qx') }}</el-button>
        <el-button v-preventReClick :loading="subLoading" type="primary" @click="confirmAddGoodsType">{{ $t('message.qr') }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :title="$t('message.pldr')"
      :visible.sync="isShow"
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      width="30%"
      center
      @close="clearUp"
    >
      <el-upload
        ref="excel-upload-input"
        :action="uploadFileUrl"
        :limit="1"
        :data="uploadData"
        :auto-upload="true"
        accept=".xlsx, .xls"
        :on-change="fileChange"
        :on-success="handleSuccess"
        :on-error="handleError"
        :on-remove="removeFile"
        :file-list="fileList"
      >
        <el-button size="small" plain>{{ $t('message.xzwj') }}</el-button>
        <div slot="tip" class="el-upload__tip">{{ $t('message.znscbg') }}</div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="true" @click="downLoad">{{ $t('message.xzmb') }}</el-button>
        <el-button v-preventReClick type="primary" @click="submit">{{ $t('message.qr') }}</el-button>
      </span>
    </el-dialog>

    <el-dialog :title="$t('message.drxxcw')" :visible.sync="isError" width="30%" center :close-on-click-modal="modalDialog" :close-on-press-escape="modalDialog">
      <div v-for="(item, index) in errList" :key="index">{{ item }}</div>
      <span slot="footer" class="dialog-footer">
        <el-button v-preventReClick type="primary" @click="close">{{ $t('message.qr') }}</el-button>
      </span>
    </el-dialog>

    <el-dialog :title="$t('message.gggl')" :visible.sync="sku" width="800px" center :close-on-click-modal="modalDialog" :close-on-press-escape="modalDialog">
      <el-table
        v-loading="listLoading"
        :data="skuNameList"
        element-loading-text="Loading"
        border
        fit
        :header-row-class-name="'table-header'"
        class="doumee-element-table margin-t-20"
      >
        <el-table-column
          align="center"
          :label="$t('message.ggm')"
          prop="name"
          min-width="200"
        />
        <el-table-column
          align="center"
          :label="$t('message.guige')"
          prop="vals"
          min-width="200"
        />
        <el-table-column
          :label="$t('message.caozuo')"
          min-width="250"
          align="center"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              v-preventReClick
              type="text"
              @click="toEditSkuName(row)"
            >{{ $t('message.edit') }}</el-button>
            <el-button
              v-preventReClick
              type="text"
              @click="toSkuVal(row)"
            >{{ $t('message.ggz') }}</el-button>
            <el-button
              v-preventReClick
              type="text"
              class="secondColor"
              @click="toDeleteSkuName(row.id)"
            >{{ $t('message.del') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="addSkuAction">{{ $t('message.xzgg') }}</el-button>
        <el-button v-preventReClick type="primary" @click="sku=false">{{ $t('message.qr') }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :title="isNameAdd ? $t('message.add') + $t('message.ggmc') : $t('message.edit') + $t('message.ggmc')"
      :visible.sync="addSku"
      width="40%"
      center
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      @closed="closeSku"
    >
      <el-form ref="skuNameForm" :model="skuNameForm" label-width="auto" label-suffix="：" :rules="skuNameRules">
        <el-form-item :label="$t('message.ggmc')" prop="name">
          <el-input v-model="skuNameForm.name" :placeholder="$t('message.qsr') + $t('message.ggmc')" />
        </el-form-item>
        <el-form-item :label="$t('message.sort')" prop="sort">
          <el-input v-model="skuNameForm.sort" :placeholder="$t('message.qsr') + $t('message.sort')" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick type="primary" @click="editAddSkuNameAction">{{ $t('message.qr') }}</el-button>
        <el-button @click="addSku=false">{{ $t('message.qx') }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :title="$t('message.ggzgl')"
      :visible.sync="addSkuVal"
      width="40%"
      center
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      @close="getSkuNameList"
    >
      <el-form ref="skuValForm" v-model="skuValForm" inline label-suffix="：">
        <el-form-item :label="$t('message.ggmc')" prop="name">
          {{ skuValForm.name }}
        </el-form-item>
        <div class="sku-title">{{ $t('message.ggz') }}</div>
        <el-form-item v-for="(item, index) in skuValList" :key="index">
          <el-input v-model="item.val" class="sku-value" :placeholder="$t('message.qsr') + $t('message.ggz')" />
          <el-input v-model="item.sort" class="sku-value" :placeholder="$t('message.qsr') + $t('message.sort')" />
          <el-button v-preventReClick type="text" @click="saveSkuVal(item)">{{ $t('message.baocun') }}</el-button>
          <el-button v-if="item.id" type="text" class="secondColor" @click="delSkuVal(item.id)">{{ $t('message.del') }}</el-button>
        </el-form-item>
        <div>
          <el-button type="text" @click="addSkuValAction()">{{ $t('message.tijia') }}</el-button>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick type="primary" @click="addSkuVal=false">{{ $t('message.qr') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  uploadFile,
  getGoodsTemplateExcel,
  batchImportByExcel,
  goodsClassifySave,
  goodsClassifyListVenue,
  goodsClassifyEditSave,
  goodsClassifyRemove,
  goodsListVenue,
  goodsDiscount,
  goodsRemove,
  goodsStatusEdit,
  goodsStatusEdit1,
  goodsSkuNameEditSave, goodsSkuNameList, goodsSkuNameRemove, goodsSkuNameSave,
  goodsSkuValEditSave, goodsSkuValList, goodsSkuValRemove, goodsSkuValSave
} from '@/api'
import store from '@/store'
export default {
  name: 'VarietySet',
  data() {
    return {
      goodsRestaurantId: '',
      modalDialog: store.getters.dialog,
      subLoading: false,
      meta: [],
      fileList: [],
      fileUrl: '',
      uploadData: {
        folder: 'PUBLIC_IMG',
        type: ''
      },
      isError: false,
      errList: [],
      uploadFileUrl: uploadFile,
      isShow: false,
      totalCount: 0,
      listLoading: true,
      goodsList: [],
      pagination: {
        page: 1,
        rows: 10
      },
      discountInfo: '',
      goodsTypeAddEdit: true,
      showAddGoodsType: false,
      activeGoodsType: {},
      goodsType: [],
      goodsTypeInfo: {
        name: '',
        sort: '',
        saleType: [],
        venueId: sessionStorage.getItem('venueId')
      },
      selectGoodsTypeInfo: {},
      filters: {
        goodsName: '',
        checkGoodsStatus: null,
        goodsStatus: [
          { value: '', label: this.$t('message.qb') },
          { value: '1', label: this.$t('message.shanjia') },
          { value: '0', label: this.$t('message.xiajia') }
        ]
      },
      saleTypes: [
        { name: this.$t('message.caipin'), id: '0' },
        { name: this.$t('message.caipin'), id: '1' }
      ],
      sku: false,
      addSku: false,
      rules: {
        saleType: [
          { required: true, message: this.$t('message.qxz') + this.$t('message.xsqd'), trigger: 'change' }
        ],
        name: [
          { required: true, message: this.$t('message.qsr') + this.$t('message.flmc'), trigger: 'blur' }
        ],
        sort: [
          { required: true, message: this.$t('message.qsr') + this.$t('message.sort'), trigger: 'blur' }
        ]
      },
      skuRules: {},
      skuNameList: [],
      isNameAdd: false,
      skuNameForm: {
        name: '',
        sort: ''
      },
      skuNameRules: {
        name: [
          { required: true, message: this.$t('message.qsr') + this.$t('message.ggmc'), trigger: 'blur' }
        ],
        sort: [
          { required: true, message: this.$t('message.qsr') + this.$t('message.sort'), trigger: 'blur' }
        ]
      },
      addSkuVal: false,
      skuValForm: {},
      skuValList: []
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.goodsRestaurantId = this.$route.query.id || ''
    this.getClassifyList()
  },
  activated() {
    this.meta = this.$route.meta.buttons || []
    this.goodsRestaurantId = this.$route.query.id || ''
    this.getClassifyList()
  },
  methods: {
    showSKU() {
      this.sku = true
      this.getSkuNameList()
    },
    getSkuNameList() {
      goodsSkuNameList({
        param: {
          venueId: sessionStorage.getItem('venueId'),
          saleType: 1,
          goodsRestaurantId: this.goodsRestaurantId
        }
      })
        .then(res => {
          // console.log(res);
          if (res.errorCode === '000000') {
            this.skuNameList = res.recordList
          }
        })
    },
    addSkuAction() {
      this.isNameAdd = true
      this.addSku = true
    },
    toEditSkuName(row) {
      this.addSku = true
      this.isNameAdd = false
      this.skuNameForm = { ...row }
    },
    editAddSkuNameAction() {
      // console.log(this.skuNameForm);
      this.$refs.skuNameForm.validate((v) => {
        if (v) {
          const skuNameAction = this.isNameAdd ? goodsSkuNameSave : goodsSkuNameEditSave
          skuNameAction({
            param: {
              ...this.skuNameForm,
              venueId: sessionStorage.getItem('venueId'),
              goodsRestaurantId: this.goodsRestaurantId,
              saleType: 1
            }
          })
            .then(res => {
              if (res.errorCode !== '000000') return
              this.addSku = false
              this.getSkuNameList()
            })
        }
      })
    },
    closeSku() {
      // console.log(this.skuNameForm);
      this.skuNameForm = {
        name: '',
        sort: ''
      }
      // console.log(this.skuNameForm);
    },
    toDeleteSkuName(id) {
      goodsSkuNameRemove({ param: { id }})
        .then(res => {
          if (res.errorCode === '000000') {
            this.$message.success(this.$t('message.delcg'))
            this.getSkuNameList()
          } else {
            this.$message.success(res.errorMsg)
          }
        })
    },
    toSkuVal(row) {
      this.skuValForm = row
      this.addSkuVal = true
      this.getSkuValList()
    },
    getSkuValList() {
      goodsSkuValList({
        param: { goodsSkuId: this.skuValForm.id }
      })
        .then(res => {
          if (res.errorCode === '000000') {
            this.skuValList = res.recordList
          }
        })
    },
    addSkuValAction() {
      this.skuValList.push({
        val: '',
        sort: ''
      })
    },
    saveSkuVal(item) {
      if (item.val === '') {
        this.$message.error(this.$t('message.qsr') + this.$t('message.ggz'))
        return
      }
      if (item.sort === '') {
        this.$message.error(this.$t('message.qsr') + this.$t('message.sort'))
        return
      }
      if (item.id) {
        // 编辑
        goodsSkuValEditSave({
          param: {
            ...item
          }
        })
          .then(res => {
            if (res.errorCode === '000000') {
              this.$message.success(this.$t('message.editcg'))
              this.getSkuValList()
            } else {
              this.$message.success(res.errorMsg)
            }
          })
      } else {
        // 新增
        goodsSkuValSave({
          param: {
            ...item,
            goodsSkuId: this.skuValForm.id
          }
        })
          .then(res => {
            if (res.errorCode === '000000') {
              this.$message.success(this.$t('message.addcg'))
              this.getSkuValList()
            } else {
              this.$message.success(res.errorMsg)
            }
          })
      }
    },
    delSkuVal(id) {
      goodsSkuValRemove({ param: { id }})
        .then(res => {
          if (res.errorCode === '000000') {
            this.$message.success(this.$t('message.delcg'))
            this.getSkuValList()
          } else {
            this.$message.success(res.errorMsg)
          }
        })
    },
    // 场馆端菜品分类列表
    getClassifyList() {
      goodsClassifyListVenue({
        param: {
          venueId: sessionStorage.getItem('venueId'),
          saleType: 1,
          goodsRestaurantId: this.goodsRestaurantId
        }
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.goodsType = res.recordList
          if (this.goodsType) {
            this.selectGoodsTypeInfo = this.goodsType[0]
            this.getGoodsListByType()
          }
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    // 场馆端菜品分类列表
    getGoodsListByType() {
      const { pagination } = this
      goodsListVenue({
        pagination,
        param: {
          classifyId: this.selectGoodsTypeInfo.id,
          name: this.filters.goodsName,
          status: this.filters.checkGoodsStatus,
          venueId: sessionStorage.getItem('venueId')
        }
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.goodsList = res.recordList
          this.totalCount = res.totalCount
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    handleCurrentChange(val) {
      // console.log(`当前页:`, val)
      this.pagination.page = val
      this.getGoodsListByType()
    },
    pageSizeChange(val) {
      this.pagination.rows = val
      this.getGoodsListByType()
    },
    toShow(scope) {
      // 展示折扣详情
      // list
      goodsDiscount({ param: { id: scope.row.id }}).then((res) => {
        if (res.errorCode !== '000000') return
        const discountInfo = res.recordList
        var memprice = ''
        discountInfo.forEach((item) => {
          memprice = memprice + item.cardName + ':' + item.memberPrice + ' \n '
        })
        this.discountInfo = memprice
        console.log(this.discountInfo)
      })
    },
    // 启用或禁用
    editStatus(id, status) {
      if (status === '0') {
        goodsStatusEdit({
          param: {
            id
          },
          userId: sessionStorage.getItem('userId')
        })
          .then((res) => {
            if (res.errorCode === '000000') {
              this.getGoodsListByType()
            }
          })
          .catch((err) => {
            console.log(err)
          })
      } else {
        goodsStatusEdit1({
          param: {
            id
          },
          userId: sessionStorage.getItem('userId')
        })
          .then((res) => {
            console.log(res)
            if (res.errorCode === '000000') {
              this.getGoodsListByType()
            }
          })
          .catch((err) => {
            console.log(err)
          })
      }
    },
    // 删除
    toDelete(id) {
      const that = this
      this.$confirm(this.$t('message.sccptc'), this.$t('message.ts'), {
        confirmButtonText: this.$t('message.qd'),
        cancelButtonText: this.$t('message.qx'),
        type: 'warning',
        callback: () => {},
        beforeClose: (action, ctx, close) => {
          if (action !== 'confirm') {
            close()
            return
          }
          ctx.confirmButtonLoading = true
          goodsRemove({ param: { id }, userId: sessionStorage.getItem('userId') }).then((res) => {
            ctx.confirmButtonLoading = false
            close()
            if (res.errorCode === '000000') {
              that.$message.success(this.$t('message.delcg'))
              that.getGoodsListByType()
            }
          })
            .catch(() => { ctx.confirmButtonLoading = false })
        }
      }).finally(() => {})
    },
    addGoodsType() {
      this.goodsTypeAddEdit = true
      this.showAddGoodsType = true
    },
    cancelAddGoodsType() {
      this.goodsTypeInfo = { name: '', sort: '', saleType: [] }
      this.$refs.form.clearValidate()
    },
    confirmAddGoodsType() {
      if (this.goodsTypeAddEdit) {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.subLoading = true
            goodsClassifySave({
              param: {
                venueId: sessionStorage.getItem('venueId'),
                name: this.goodsTypeInfo.name,
                sort: this.goodsTypeInfo.sort,
                saleType: 1,
                goodsRestaurantId: this.goodsRestaurantId
                // saleType: this.goodsTypeInfo.saleType.join(',')
              }
            })
              .then((res) => {
                if (res.errorCode !== '000000') return
                this.showAddGoodsType = false
                this.subLoading = false
                this.getClassifyList()
              }, () => {
                this.subLoading = false
              })
          } else {
            this.subLoading = false
            console.log('error submit!!')
            return false
          }
        })
      } else {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.subLoading = true
            goodsClassifyEditSave({
              param: {
                id: this.goodsTypeInfo.id,
                classifyName: this.goodsTypeInfo.name,
                sort: this.goodsTypeInfo.sort,
                saleType: 1,
                goodsRestaurantId: this.goodsRestaurantId
              }
            })
              .then((res) => {
                this.subLoading = false
                if (res.errorCode !== '000000') return
                this.showAddGoodsType = false
                this.getClassifyList()
              })
              .catch(() => {
                this.subLoading = false
              })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    },
    selectGoodsType(item) {
      this.selectGoodsTypeInfo = item
      this.showGoodsListByType()
    },
    showGoodsListByType() {
      this.getGoodsListByType()
    },
    toEditGoodsType(item) {
      this.goodsTypeInfo = { ...item, saleType: item.saleType.split(',') }
      this.goodsTypeAddEdit = false
      this.showAddGoodsType = true
    },
    toDeleteGoodsType(item) {
      const that = this
      this.$confirm(this.$t('message.sccpfltc'), this.$t('message.ts'), {
        confirmButtonText: this.$t('message.qd'),
        cancelButtonText: this.$t('message.qx'),
        type: 'warning',
        callback: () => {},
        beforeClose: (action, ctx, close) => {
          if (action !== 'confirm') {
            close()
            return
          }
          ctx.confirmButtonLoading = true
          goodsClassifyRemove({ param: { id: item.id }}).then((res) => {
            ctx.confirmButtonLoading = false
            close()
            if (res.errorCode === '000000') {
              that.$message.success(this.$t('message.delcg'))
              that.getClassifyList()
            }
          })
            .catch(() => { ctx.confirmButtonLoading = false })
        }
      }).finally(() => {})
    },
    inBatch() {
      this.isShow = true
    },
    downLoad() {
      getGoodsTemplateExcel({ param: { type: 1 }}).then(res => {
        console.log(res)
        if (res.errorCode === '000000') {
          window.open(res.record, '_blank')
        }
      }).catch(err => {
        console.log(err)
      })
    },
    clearUp() {

    },
    submit() {
      if (this.fileUrl.length === 0) {
        this.$message.error(this.$t('message.qxxzwj'))
        return
      }
      // excelPath
      batchImportByExcel({ param: { excelPath: this.fileUrl, goodsRestaurantId: this.goodsRestaurantId }, userId: sessionStorage.getItem('userId') }).then(res => {
        console.log(res)
        this.isShow = false
        if (res.errorCode === '000000') {
          this.getClassifyList()
          // this.uploadFileUrl = ''
          this.fileList = []
          this.fileUrl = ''
          if (res.record.errList.length) {
            this.errList = res.record.errList
            this.isError = true
          }
        }
      }).catch(err => {
        console.log(err)
        this.getClassifyList()
      })
    },
    close() {
      this.isError = false
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: this.$t('message.jingao'),
        message: this.$t('message.znxzygwj') + ` ${files.length + fileList.length} ` + this.$t('message.gei')
      })
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      console.log('change', file, fileList)
      // const formDate = new FormData()
      // formDate.append('file', file)
      // Axios.post(this.uploadFileUrl, formDate).then(res => {
      //   console.log(res)
      // })
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      console.log('before upload')
      // const extension = file.name.substring(file.name.lastIndexOf('.') + 1)
      const size = file.size / 1024 / 1024
      if (size > 10) {
        this.$notify.warning({
          title: this.$t('message.jingao'),
          message: this.$t('message.wjdabndy10')
        })
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      // console.log('成功', fileList)
      this.fileList = fileList
      this.fileUrl = file.response.showUrl
      console.log(this.fileUrl)
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      // console.log(this.$t('message.cw'))
      debugger
      this.$notify.error({
        title: this.$t('message.cw'),
        message: this.$t('message.wjscsb')
      })
      console.log(err, file, fileList)
    },
    // 文件移除
    removeFile(file, fileList) {
      console.log('移除')
      this.fileUrl = ''
    },
    addGoods() {
      this.$router.push({ name: 'VarietyAdd', query: { goodsRestaurantId: this.goodsRestaurantId }})
    },
    // 编辑
    toEdit(id) {
      const goodsRestaurantId = this.goodsRestaurantId
      this.$router.push({ name: 'VarietyAdd', query: { id: id, goodsRestaurantId }})
    },
    handleFilter() {
      this.pagination.page = 1
      this.getGoodsListByType()
    },
    goBack() {
      this.$router.replace(`/application/ordering`)
    },
    clear() {
      this.filters.goodsName = ''
      this.filters.checkGoodsStatus = null
      this.pagination.page = 1
      this.getGoodsListByType()
    }
  }
}

</script>

<style lang="scss" scoped>
@import "@/styles/variables.scss";
.division-line {
  text-align: center;
  display: inline-block;
  color: #999;
  width: 20px;
  margin-right: 10px;
}
.goosmanager-space-box {
  display: flex;
  position: relative;
  height:calc(100% - 78px);
  box-sizing: border-box;
  .box-item {
    // position: absolute;
    .goodstype-item {
      background-color: #f7f7f7;
      padding: 20px;
      border-radius: 4px;
      margin-top: 5px;
      margin-right: 10px;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      .popItems {
        display: flex;
        flex-direction: column;
        // align-items: flex-start;
        // justify-content: flex-start;
      }
    }
    .goodstype-item.active {
      border: 1px solid $menuActive;
      background-color: #f4f7fc;
    }
    .add-goodstype-btn {
      // position: absolute;
      // bottom: 0;
      // left: 55px;
      width: 150px;
      margin-top: 20px;
      margin-left: 55px;
    }
  }
  .box-item.goodstype {
    width: 300px;
    // padding-right: 30px;
    margin-right: 20px;
    height: 100%;
    overflow-y: auto;
  }
  .box-item.goodsinfo {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    min-width: 0;
  }
}
.pre {
  white-space: pre;
  .discount-title {
    color: #303133;
    font-size: 16px;
    margin-bottom: 12px;
  }
}
.sku-title  {
  height: 24px;
  line-height: 24px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 500;
}
.sku-value {
  margin-right: 10px;
  width: 180px;
}

/**
*/
</style>
